<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>ref 定义的未初始化数组可以被监听</title>
</head>
<body>
<div id="app">
    <button v-on:click="pushArray">添加元素</button>
    <button v-on:click="modifyArray">修改元素</button>
</div>

<script type="module">
    import {createApp, ref, watch} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {
                let array = ref([])

                watch(
                    array.value,
                    () => {
                        console.log(array.value);
                    }
                )

                function pushArray() {
                    console.log("添加一个元素");
                    array.value.push(6)

                }

                function modifyArray() {
                    array.value.splice(0, 0, 9)
                }

                return {
                    array, pushArray, modifyArray,
                }
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>